package com.yonyou.cyxdms.basedata.service.controller.option;

    import com.yonyou.cyxdms.basedata.client.domains.vo.PackageCacheVO;
    import com.yonyou.cyxdms.basedata.client.domains.vo.VsOptionVO;
    import com.yonyou.cyxdms.basedata.service.entity.option.VsOptionPO;
    import com.yonyou.cyxdms.basedata.service.vo.packages.PackageDictVO;
    import org.springframework.web.bind.annotation.*;
        import com.yonyou.cyx.framework.controller.base.BaseController;
    
    
    
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

import com.yonyou.cyxdms.basedata.service.service.option.VsOptionService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

import com.yonyou.cyxdms.basedata.service.dto.option.VsOptionDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;






 /**
 *选装
 * @author zys
 * @since 2020-02-10
 */
@RestController
@RequestMapping("/option/vsOption")
public class VsOptionController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(VsOptionController.class);

    @Autowired
    public VsOptionService vsOptionService;

    /**
     * 分页查询数据
     *
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author zys
     * @since 2020-02-10
     */
    @ResponseBody
    @GetMapping
    @SuppressWarnings("unchecked")
    public IPage<Map<String,Object>> getList (@RequestParam Map<String,Object> queryCondition, @RequestParam
        ("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        Page<Map<String,Object>> page = new Page(currentPage, pageSize);
        return vsOptionService.selectPageBysql(page, queryCondition);
    }

    /**
     * 进行数据修改
     *
     * @param id 数据主键ID
     * @return  Map<String,Object> 数据对应的map 结构
     * @author zys
     * @since 2020-02-10
     */
    @ResponseBody
    @GetMapping(value="/{id}")
    @SuppressWarnings("unchecked")
    public Map<String,Object> getById(@PathVariable("id") Long id) {
        return vsOptionService.getById(id);
    }

    /**
     * 进行数据新增
     *
     * @param vsOptionDTO 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author zys
     * @since 2020-02-10
     */
    @ResponseBody
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String,Object> insert(@RequestBody VsOptionDTO vsOptionDTO) {
        logger.debug("vsOptionDTO:{}",vsOptionDTO);
        return vsOptionService.insert( vsOptionDTO);
    }

    /**
     * 进行数据修改
     *
     * @param id 需要修改数据的ID
     * @param vsOptionDTO 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author zys
     * @since 2020-02-10
     */
    @ResponseBody
    @PutMapping(value="/{id}")
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String,Object> update(@PathVariable("id") Long id, @RequestBody VsOptionDTO vsOptionDTO) {
        logger.debug("vsOptionDTO:{}",vsOptionDTO);
        return vsOptionService.update(id,vsOptionDTO);
    }

    /**
     * 根据id删除对象
     *
     * @param id 需要修改数据的ID
     * @author zys
     * @since 2020-02-10
     */
    @DeleteMapping(value="/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteById(@PathVariable("id") Long id){
        logger.debug("删除ID:{}",id);
        vsOptionService.deleteById(id);
        return true;
    }

    /**
     * 根据IDs批量删除对象
     *
     * @param ids 需要修改数据的ID集合
     * @author zys
     * @since 2020-02-10
     */
    @DeleteMapping(value="/batch/{ids}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteByIds(@PathVariable("ids") String ids){
        logger.debug("删除ID:{}",ids);
        vsOptionService.deleteBatchIds(ids);
        return true;
    }
    
    
    /**
     * 根据packageId查询对应选装信息
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
})
    @GetMapping("/getOptionByPackageId/{packageId}")
    public List<Map<String,Object>> getOptionByPackageId(@PathVariable("packageId") Long packageId){
    	return vsOptionService.getOptionByPackageId(packageId);
    }
    
    
    /**
     * 根据packageId查询对应选装信息(APP使用)
     */
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    @GetMapping("/getOptionByPackageId")
    public List<Map<String,Object>> getOptionByPackageIdForApp(@RequestParam Long packageId){
    	return vsOptionService.getOptionByPackageId(packageId);
    }

     /**
      * 按条件查询选装信息
      *
      */
     @GetMapping(value="/queryOptionByCondition")
     public List<VsOptionVO> queryOptionByCondition(@RequestParam Map<String, Object> queryParam) {
         return vsOptionService.queryOptionByCondition(queryParam);
     }

     /**
      *
      * 查询所有配置
      */
     @GetMapping(value="/queryAllOption")
     public List<VsOptionVO> queryAllOption() {
         return vsOptionService.queryAllOption();
     }

     /**
      *
      * 查询所有配置
      */
     @GetMapping(value="/queryAllPackage")
     public List<PackageDictVO> queryAllPackage() {
         return vsOptionService.queryAllPackage();
     }


}